import serialEasy 
from pymongo import Connection
import time

## This already writes to the database, it updates it!


connection = Connection()
db = connection.string0001
sensors = db.NIsensors
bma = "1,2,3,4"


while True:
	a = serialEasy.ser.readlines()
	if a != []:
		tSum = 0
		bma = str(a[0])
		bma = bma.split(",")
		writer = ({"label" : 0})
		
		for i in  range(0,4):
			ii = str(i)
			tSum = tSum + int(bma[i])
			writer.update ({ 'Niv' + ii : int(bma[i]), 'tSum' : tSum })
			
		sensors.update({'label' : 0}, writer, True)
		print bma
		print tSum
		
		
